package com.itheima.tcpdemo3;

import java.io.DataInputStream;
import java.net.Socket;

public class ServerReader extends Thread{
    private Socket socket;

    public ServerReader(Socket socket) {
        this.socket = socket;
    }

    @Override
    public void run() {
        try {
            DataInputStream dis = new DataInputStream(socket.getInputStream());
            while (true) {
                if(dis.available() > 0){
                    System.out.println("客户端说：" + dis.readUTF());
                    System.out.println("客户端的ip为：" + socket.getInetAddress());
                    System.out.println("客户端的端口为：" + socket.getPort());
                    System.out.println("------------------------------------------");
                }
            }
        } catch (Exception e) {
            System.out.println("客户端断开连接");
        }
    }
}
